package com.dmpp.mes.service.impl;


import com.dmpp.mes.bean.RespEnum;
import com.dmpp.mes.bean.ResponseData;
import com.dmpp.mes.dao.DeviceCategoryMapper;
import com.dmpp.mes.dao.ProcessMapper;
import com.dmpp.mes.parameterInfo.DeviceCategory;
import com.dmpp.mes.parameterInfo.Process;
import com.dmpp.mes.service.DeviceCategoryService;
import com.dmpp.mes.service.ProcessService;
import com.github.pagehelper.PageInfo;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value = "ProcessService")
public class ProcessServiceImpl implements ProcessService {


    @Autowired
    private ProcessMapper mapper;

    @Override
    public ResponseData findAll(Process process) {
        ResponseData responseData = new ResponseData();
        PageInfo pageInfo = new PageInfo<>(mapper.findAll(process));
        responseData.setData(pageInfo);
        return responseData;
    }

    @Override
    public ResponseData findByCode(String code) {
        ResponseData responseData = new ResponseData();
        responseData.setData(mapper.findByCode(code));
        return responseData;
    }

    @Override
    public ResponseData insert(Process process) {
        ResponseData responseData = new ResponseData();
        Process process1 = mapper.findByCode(process.getCode());
        if(process1==null)
        {
            mapper.insert(process);
        }else {
            responseData.setCodeEnum(RespEnum.ERROR2001);
        }

        return responseData;
    }

    @Override
    public ResponseData updateById(Process process) {
        ResponseData responseData = new ResponseData();
        mapper.updateById(process);
        return responseData;
    }

    @Override
    public ResponseData delete(String code) {
        ResponseData responseData = new ResponseData();
        mapper.delete(code);
        return responseData;
    }
}
